package com.kim.smartring.activity.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.kim.smartring.R;
import com.kim.smartring.activity.SmartRingMainActivity;

/**
 * ���˵���fragment
 * 
 */
public class MenuFragment extends Fragment implements OnClickListener {

	private static final String TAG = "MenuFragment";

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.left_drawer_fragment, null);
		initView(v);
		return v;
	}

	private void initView(View v) {
		v.findViewById(R.id.ll_main).setOnClickListener(this);
		v.findViewById(R.id.ll_heart).setOnClickListener(this);
		v.findViewById(R.id.ll_target).setOnClickListener(this);
		v.findViewById(R.id.ll_lost).setOnClickListener(this);
		v.findViewById(R.id.ll_info).setOnClickListener(this);
		v.findViewById(R.id.ll_alert).setOnClickListener(this);
		v.findViewById(R.id.ll_bind).setOnClickListener(this);
		v.findViewById(R.id.ll_feedback).setOnClickListener(this);
		v.findViewById(R.id.btn_login_register).setOnClickListener(this);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

	}

	// �л�Fragment��ͼ��ring
	private void switchFragment(Fragment fragment) {
		if (getActivity() == null)
			return;

		if (getActivity() instanceof SmartRingMainActivity) {
			SmartRingMainActivity fca = (SmartRingMainActivity) getActivity();
			fca.switchContent(fragment);
		}
	}

	@Override
	public void onClick(View arg0) {
		Fragment newContent = null;
		switch (arg0.getId()) {
		case R.id.ll_main:
			newContent = new SmartRingMainFragment();
			break;
		case R.id.ll_heart:
			newContent = new HeartRateFragment();
			break;
		case R.id.ll_target:
			newContent = new TargetFragment();
			break;
		case R.id.ll_lost:
			newContent = new LossFragment();
			break;
		case R.id.ll_info:
			newContent = new PersonInfoFragment();
		case R.id.ll_alert:
			newContent = new AlarmSettingsFragment();
			break;
		case R.id.ll_bind:
			newContent = new BindFragment();
			break;
		case R.id.ll_feedback:
			newContent = new FeedBackFragment();
			break;
		case R.id.btn_login_register:
			newContent = new LoginFragment();
			break;

		default:
			break;
		}
		if (newContent != null) {
			switchFragment(newContent);
		}

	}

}
